from django.db import models

class CardwallUser(models.Model):
    pass

class Wall(models.Model):
    title = models.CharField(max_length=50)
    #fk_owner = models.ForeignKey(CardwallUser)
    #fk_story = 0
    status = models.CharField(max_length=1, default='I')  #I- Inbox, T- Trash, A-Archived, D-Destroyed
    owner = models.CharField(max_length=50, null=True)
    date_created = models.DateField()
    description = models.CharField(max_length=400, null=True)

    def get_active_stages(self):
        active_stages = Stage.objects.filter(fk_wall=self, 
                                             is_active=True).order_by('order_no')
        return active_stages

    def __unicode__(self):
        return self.title

class Stage(models.Model):
    title = models.CharField(max_length=15)
    fk_wall = models.ForeignKey(Wall)
    #date_created = models.DateField()
    is_active = models.BooleanField(default=True)
    order_no = models.IntegerField()
    description = models.CharField(max_length=200, null=True)

    def get_active_cards(self):
        active_cards = Card.objects.filter(fk_stage=self,
                                           status='I').order_by('date_created')
        return active_cards

    def __unicode__(self):
        return self.title

class Card(models.Model):
    title = models.CharField(max_length=20)
    fk_stage = models.ForeignKey(Stage)
    date_created = models.DateField()
    start_date = models.DateField(blank=True, null=True)
    end_date = models.DateField(blank=True, null=True)
    developers = models.CharField(max_length=60, null=True)
    #points = models.CharField(max_length=2, null=True)
    status = models.CharField(max_length=1, default='I')  #I- Inbox, T- Trash, A-Archived, D-Destroyed
    description = models.CharField(max_length=100, null=True)

    def move(self, new_stage):
        self.fk_stage = new_stage
        self.save()

    def __unicode__(self):
        return self.title

class CardMove(models.Model):
    fk_card = models.ForeignKey(Card)
    #fk_user = models.ForeignKey(CardwallUser)
    date_time = models.DateTimeField()
    #initial_stage = models.ForeignKey(Stage)
    final_stage = models.ForeignKey(Stage)

class CardDevelopers(models.Model):
    fk_card = models.ForeignKey(Card)
    #fk_developer = models.ForeignKey(CardwallUser)

class CardComments(models.Model):
    fk_card = models.ForeignKey(Card)
    date_created = models.DateField()
    #fk_author = models.ForeignKey(CardwallUser)
    author = models.CharField(max_length=30, null=True)
    comment = models.CharField(max_length=100, null=True)
